cssimagecrossfade: Don't abort() when failing to parse image
authorBenjamin Otte <otte@redhat.com>
Fri, 16 Jul 2021 15:48:25 +0000 (17:48 +0200)
committerBenjamin Otte <otte@redhat.com>
Fri, 16 Jul 2021 15:50:09 +0000 (17:50 +0200)
The code wasn't checking if parsing an image failed and just returning
success.

Testcase from bug is attached.

Fixes #4101

gtk/gtkcssimagecrossfade.c
testsuite/css/parser/cross-fade-crash-4101.css [new file with mode: 0644]
testsuite/css/parser/cross-fade-crash-4101.errors [new file with mode: 0644]
testsuite/css/parser/cross-fade-crash-4101.ref.css [new file with mode: 0644]
testsuite/css/parser/meson.build

index fadd11331d1eff7a21f4a8067ade67ab5bee4c13..6953606c8edf6943c419b437c199fcca2d0df0ec 100644 (file)
@@ -312,7 +312,13 @@ parse_image (GtkCssParser *parser,
   GtkCssImage **image = option_data;
 
   if (_gtk_css_image_can_parse (parser))
-    *image = _gtk_css_image_new_parse (parser);
+    {
+      *image = _gtk_css_image_new_parse (parser);
+      if (*image == NULL)
+        return FALSE;
+
+      return TRUE;
+    }
   else if (gtk_css_color_value_can_parse (parser))
     {
       GtkCssValue *color;
@@ -322,11 +328,11 @@ parse_image (GtkCssParser *parser,
         return FALSE;
 
       *image = _gtk_css_image_fallback_new_for_color (color);
-    }
-  else
-    return FALSE;
 
-  return TRUE;
+      return TRUE;
+    }
+  
+  return FALSE;
 }
 
 static guint
diff --git a/testsuite/css/parser/cross-fade-crash-4101.css b/testsuite/css/parser/cross-fade-crash-4101.css
new file mode 100644 (file)
index 0000000..79180f9
--- /dev/null
@@ -0,0 +1,3 @@
+a {
+  background: cross-fade(8% -gtk-icontheme("system-run-symbolic"), image());
+}
diff --git a/testsuite/css/parser/cross-fade-crash-4101.errors b/testsuite/css/parser/cross-fade-crash-4101.errors
new file mode 100644 (file)
index 0000000..25d4bec
--- /dev/null
@@ -0,0 +1 @@
+cross-fade-crash-4101.css:2:74-75: error: GTK_CSS_PARSER_ERROR_SYNTAX
diff --git a/testsuite/css/parser/cross-fade-crash-4101.ref.css b/testsuite/css/parser/cross-fade-crash-4101.ref.css
new file mode 100644 (file)
index 0000000..e69de29
index 2d476f018dbb213d5b210ee641703ae9c5df85f4..e161d48835771844c82f1cab8c23754a855eb082 100644 (file)
@@ -212,6 +212,9 @@ test_data = [
   'comment-detection.css',
   'comment-detection.ref.css',
   'cross-fade-basic.css',
+  'cross-fade-crash-4101.css',
+  'cross-fade-crash-4101.errors',
+  'cross-fade-crash-4101.ref.css',
   'css-21-malformed-declarations.css',
   'css-21-malformed-declarations.errors',
   'css-21-malformed-declarations.ref.css',